<?php
class Core_Data_Mappers_Studentlist extends Core_Data_Mappers_Abstract {
	protected $_map = array("Trainingsessionid"=>"trainingsessionid","Studentid"=>"studentid");
	protected  $_businessclass="Core_Business_Studentlist";
	protected  $_modelclass = "Core_Data_Models_Studentlist";
		
	
	
	/**
	 * return the Core_Business_Studentlist object with the id pass in argument
	 * @param $id int identifier of studentlist
	 * return null|Core_Business_Studentlist
	 */
	public function find($id) {
		$row = $this->getDbTable()->fetchAll(array("id = ?"=>$id));
		if (isset($row)) {
			$o = $this->map($row);
			return $o;
		}
		return null;	
	}
	
	public function add($object){
		if($object instanceof $this->_businessclass) {
			if($this->exists($object)) {
				$data = $this->reversemap($object);
				unset($date['id']);
				$this->getDbTable()->update($data, array("id = ?"=>$object->Id));
			}
		}
	}
	
	public function edit($object){
		if($object instanceof $this->_businessclass) {
			if(!$this->exists($object)) {
				$data = $this->reversemap($object);
				unset($date['id']);
				$id = $this->getDbTable()->insert($data);
				$object->Id = $id;
			}
		}
	}
	
	public function exists($object){
		if ($object instanceof $this->_businessclass) {
			$o = $this->getDbTable()->fetchNew(array("id = ?"=>$object->Id));
			if (isset($o)) {
				return true;
			}
		}
		return false;
	}
	
	public function fetchAll($where=null,$count=10,$start=0) {
		$rows = $this->getDbTable()->fetchAll($where,null,$count,$start);
		if(isset($rows) && count($rows)>0) {
			$collection = array();
			foreach ($rows as $items) {
				$collection[] = $this->map($items);
			}
			return $collection;
		}	
		return null;
	}
}
?>